define(["require",'config/appregister',"business/special/service/http","jquery",'swiper',
"business/services/detailNavComp",
'../service/infoArea','../service/pageIndex'], function(require, app, httpServices){
	app.controller('specialCtrl',function($scope, $rootScope, $state, $stateParams,$timeout){
		$scope.infoIndex=1;
		$scope.questionIndex=1;
		$scope.courseIndex=1;
		//获取专题ID
		if(!angular.isUndefined($stateParams.subjectId)) {
			$scope.subjectId = $stateParams.subjectId;
		}
		//专题页基本信息请求和渲染
		getInfo();
		function getInfo() {
			var req = {
				type:"GET",
				uri:'getBaseInfo',
				data:{
					subjectId: $scope.subjectId
				}
			};
			httpServices.specialHttpService(req).success(function(data){
				if(!data)return;
				$scope.$apply(function(){
					if(data.code == 0) {
						$scope.path = data.data.path;
						$scope.subjectName = data.data.subjectName;
						$scope.subtitle = data.data.subtitle;
						$scope.summary = data.data.summary;
						$scope.visitCount = data.data.visitCount;
						
					}else {
						console.log(data.msg)
					}
				});
			}).error(function(){
				console.log("专题详情第一次请求失败");
			});
		};

		//关闭下载提示弹框
		$scope.guanbi = function() {
			$(".tantantan").hide();
		}
		
		
		
		
		
		//专题页目录列表请求渲染
		getInfoList();
		function getInfoList() {
			var req = {
				type:'GET',
				uri:'getInfo',
				data:{
					subjectId: $scope.subjectId
				}
			};
			httpServices.specialHttpService(req).success(function(data){
				if(!data)return;
				$scope.$apply(function(){
					if(data.code==0) {
						console.log(data);
						$scope.items = data.data;
						console.log($scope.items );
						$scope.datalength = $scope.items.length;
					}else {
						console.log(data.msg);
					}
				});
			}).error(function(){
				console.log("目录列表详情请求失败");
			});
		};
		//问答模块分页动作
		$scope.tor = function() {
			$(".span-dian").removeClass("span-dians");
			var ul1 = $(".ul1").height();
			var ul2 = $(".ul2").height();
			var ul3 = $(".ul3").height();
			if(ul1 !== 0) {
				$(".ul1").css("height","0");
				$(".ul2").css("height",'512px');
				$(".ul3").css("height","0");
				$(".dia2").addClass("span-dians");
			}
			if(ul2 !== 0) {
				$(".ul1").css("height","0");
				$(".ul2").css("height",'0');
				$(".ul3").css("height","512px");
				$(".dia3").addClass("span-dians");
			}
			if(ul3 !== 0) {
				$(".dia3").addClass("span-dians");
			}
		};
		
		$scope.tol = function() {
			$(".span-dian").removeClass("span-dians");
			var ul1 = $(".ul1").height();
			var ul2 = $(".ul2").height();
			var ul3 = $(".ul3").height();
			if(ul1 !== 0) {
				$(".dia1").addClass("span-dians");
			}
			if(ul2 !== 0) {
				$(".ul1").css("height","512px");
				$(".ul2").css("height",'0');
				$(".ul3").css("height","0");
				$(".dia1").addClass("span-dians");
			}
			if(ul3 !== 0) {
				$(".ul1").css("height","0");
				$(".ul2").css("height",'512px');
				$(".ul3").css("height","0");
				$(".dia2").addClass("span-dians");
			}			
		};
		
		
		//判断盒子颜色
		$scope.getStyle  =function(oo,tt){
			if(oo==0){
				return {
					border:"1px solid #ec251f",
					color:"#ec251f"
				};
			}else if(oo>0&&tt==1){
				return {
					border:"1px solid #35b558",
					color:"#35b558"
				};
			}else if(oo>0&&tt==2){
				return {
					border:"1px solid #ccc",
					color:"#ccc"
				};				
			}	
		};		
		//目录头部底边颜色
//		$scope.getcolor = function($index) {
//			console.log($index);
//			if($index == 0 ||$index%3 == 0){
//				var the = {
//					"border-top":"2px #ff6638 solid"
//					};
//				return the;
//			}else if($index%2 == 0){
//				var the = {"border-top":"2px #46bb99 solid !important"};
//				return the;
//			} else {
//				var the = {"border-top":"2px #30a3ff solid !important"}; 
//				return the;
//			}
//		}

		//立即下载
		$scope.filedown = function(a,b) {
			if($rootScope.userLoginInfo.logged) {
				if(!a)return alert("找不到该文件");
				
				$.ajax({
					type:"get",
					url:"http://116.62.10.111:8080/elink_user/api/user/getBaseUeserInfo?seed="+localStorage.seed+"&authToken="+localStorage.authToken,
					success:function(data) {
						if(!data)return;
						$scope.$apply(function(){
							if(data.code==0) {
								$scope.jifen = data.data.coinValue;
								if(b>$scope.jifen) {
									$(".tantantan").show();
								}else {
									var uri = "http://"+allUrl+":8083/elink_database/api/file/download?"+"fileId="+a+"&seed="+localStorage.seed+"&authToken="+localStorage.authToken;
									window.open(uri,'_blank');							
								}
							}else {
								console.log(data.msg);
							}
						});
					},
					error: function(){
						console.log("请求用户信息失败")
					}
				});
			}else {
				$(".tip-box").show();
			}

		}
		
		$scope.noxbtn = function() {
			$(".tip-box").hide();
		};
		
		$scope.tologin = function() {
			$state.go("login");
		};
		$scope.toreg = function() {
			$state.go("login",{type:"register"});
		};		
		
		//生成序列class
		$scope.domclass = function(a){
			a = a+1;
			return "swiper-container "+"swiper-1container"+a;
		}
		
		$scope.btn1class = function(a){
			a = a+1;
			return "lb-btn-l "+"lb-btn-l"+a;
		}
		
		$scope.btn2class = function(a){
			a = a+1;
			return "lb-btn-r "+"lb-btn-r"+a;
		}		
		$scope.btndivclass = function(a) {
			a = a+1;
			return "btn-div "+"btn-div"+a;
		}
		$scope.swiperclass = function(a) {
			a = a+1;
			return "swiper-container "+"swiper-2container"+a;			
		}
		$scope.mywrapper = function(a) {
			a = a+1;
			return "my-wrapper "+"my-wrapper"+a;	
		}
		$scope.lastwip = function(a) {
			a = a+1;
			return "swiper-scrollbar "+"swiper-scrollbar"+a;			
		}
	})
})
